import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { GlobalMiddle } from './middlerware/global.middleware';
import { FunctionMiddleware } from './middlerware/function.middleware';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
import { GuradGuard } from './gurad/gurad.guard';
import { Response } from './common/response';
import { httpexception } from './common/HttpException';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppInterceptor } from './app.interceptor';
import { mkdirSync } from 'fs';
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  mkdirSync(join(__dirname, 'images'));
  app.use(new GlobalMiddle().use);
  // app.use(FunctionMiddleware);
  //全局拦截器
  app.useGlobalInterceptors(new AppInterceptor());
  //全局守卫
  // app.useGlobalGuards(new GuradGuard());
  //全局拦截器
  // app.useGlobalInterceptors(new Response());
  //全局异常拦截
  // app.useGlobalFilters(new httpexception());
  const options = new DocumentBuilder()
    .setTitle('接口文档')
    .setDescription('Yui。。。')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('/api-docs', app, document);
  app.useGlobalPipes(new ValidationPipe());
  app.useStaticAssets(join(__dirname, 'images'), {
    prefix: '/yuiimg',
  });
  app.enableCors();
  await app.listen(3000);
}
bootstrap();
